package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.AppDao;
import com.qf.entity.App;
import com.qf.service.AppService;
import com.qf.service.AppService;
import com.qf.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AppServiceImpl implements AppService {
    @Autowired
    private AppDao appDao;
    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public App findApp(Integer id) {

        return appDao.findAppById(id);
    }

//    @Override
////    @Transactional(propagation = Propagation.SUPPORTS)
////    public List<App> findAll() {
////        PageHelper.startPage(1,2);
////        return AppDao.findAllApps();
////    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public PageInfo<App> findAll(PageVo pageVo ,App app) {
        PageHelper.startPage(pageVo.getPage(),pageVo.getLimit());
        List<App> apps=appDao.findAllApps(app);
        return new PageInfo<App>(apps);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer addApp(App app) {
        return appDao.insertApp(app);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer delApp(Integer[] ids) {
        return appDao.deleteApp(ids);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer updateApp(App app) {
        return appDao.updateApp(app);
    }
}
